package com.nstar.hacocwebfx.model
{
	import com.nstar.hacocwebfx.ApplicationFacade;
	import com.nstar.hacocwebfx.model.business.LoadXMLDelegate;
	import com.nstar.hacocwebfx.model.helpers.XmlResource;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.IResponder;
	import mx.utils.ObjectUtil;
	
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.proxy.Proxy;

	/**
	 * 	初始化数据配置
	 * 	如菜单等等信息
	 * 
	 */ 
	public class SamplesProxy extends Proxy implements IProxy,IResponder
	{
		public static const NAME:String = "SamplesProxy";
		private var startupMonitorProxy:StartupMonitorProxy ;
		
		public function SamplesProxy(data:Object=null)
		{
			super(NAME, data);
			
			// retrieve the StartupMonitorProxy
			startupMonitorProxy = facade.retrieveProxy( StartupMonitorProxy.NAME ) as StartupMonitorProxy;
			// add the resource to load
			startupMonitorProxy.addResource( NAME, true );			
		}
		
		public function load():void
		{
			// reset the data 
			this.data = new Object();
			// create a worker who will go get some data
			// pass it a reference to this proxy so the delegate knows where to return the data
			var delegate : LoadXMLDelegate = new LoadXMLDelegate(this,
				 'demo/data/samples.xml',"object");
			// make the delegate do some work
			delegate.load();
		}		 
		
		public function result(rpcEvent : Object):void
		{
			// call the helper class for parse the XML data
			XmlResource.parseObject(data, rpcEvent.result,"music.singer");
			// call the StartupMonitorProxy for notify that the resource is loaded
			this.startupMonitorProxy.resourceComplete( NAME );			
		}
		
		public function fault(info:Object):void
		{
			this.sendNotification( ApplicationFacade.LOAD_CONFIG_FAILED, ApplicationFacade.ERROR_LOAD_FILE );
		}		
		
		//取值
		public function getValue(key:String):ArrayCollection
		{
			return data[key.toLowerCase()];
		}
				
	}
}